package com.tju.resource.oauth.controller.tb;

import com.tju.resource.annotation.Log;
import com.tju.resource.model.TbRawMatl;
import com.tju.resource.business.tb_raw_matl.TbRawMatlService;
import com.tju.resource.result.Result;
import com.tju.resource.tool.enum_utils.FunctionType;
import com.tju.resource.tool.tool.ClientParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TbRawMatlController {
    private final static String prefix = "raw/";
    @Autowired
    private TbRawMatlService tbRawMatlService;

    /**
     * 查询原材料
     */
    @PostMapping(prefix+"list")
    @PreAuthorize("hasAuthority('sys:raw_materials:list')")
    @Log(type = FunctionType.List)
    public Result<Object> selectTbRawMatl(@RequestBody ClientParameters pars) {
        return tbRawMatlService.selectTbRawMatl(pars);
    }
    /**
     * 添加原材料
     */
    @PostMapping(prefix+"add")
    @PreAuthorize("hasAuthority('sys:raw_materials:add')")
    @Log(type = FunctionType.Add)
    public Result<Object> insertTbRawMatl(@RequestBody TbRawMatl rawMatl) {
        return tbRawMatlService.insertTbRawMatl(rawMatl);
    }
    /**
     * 修改原材料
     */
    @PostMapping(prefix+"update")
    @PreAuthorize("hasAuthority('sys:raw_materials:edit')")
    @Log(type = FunctionType.Modify)
    public Result<Object> updateTbRawMatl(@RequestBody TbRawMatl rawMatl) {
        return tbRawMatlService.updateTbRawMatl(rawMatl);
    }
    /**
     * 删除原材料
     */
    @PostMapping(prefix+"delete")
    @PreAuthorize("hasAuthority('sys:raw_materials:delete')")
    @Log(type = FunctionType.Delete)
    public Result<Object> deleteTbRawMatl(@RequestBody TbRawMatl rawMatl) {
        return tbRawMatlService.deleteTbRawMatl(rawMatl);
    }
}
